package a_02_wizhi.P_proxy.jdk;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * 此拦截器为PersonDao加强功能（添加事务）
 *
 * @author LenovoY510P
 */
public class JDKProxyInterceptor implements InvocationHandler {
    private Object target;

    public JDKProxyInterceptor(Object target) {
        super();
        this.target = target;
    }

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        /**
         * 1、开启事物 
         * 2、判断方法名，执行方法 
         */

        System.out.println("tans===== jdk proxy transaction is beginning ");
        Object invoke = method.invoke(target);
        System.out.println("tans===== jdk proxy transaction is ended ");


        System.out.println();
        System.out.println();
        return invoke;
    }

} 